package org.example.chatroom.demos.socket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;


@Configuration
@EnableWebSocket
public class WebSocketApiConfig implements WebSocketConfigurer {

    @Autowired
    private WebsocketApi websocketApi;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 通过这个方法 , 把websocket handler 注册到  具体路径上 ;
        registry.addHandler(websocketApi , "/message")
                .addInterceptors(new HttpSessionHandshakeInterceptor());

    }

}
